#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netdb.h>

#define DEFAULT_HOST "127.0.0.1"
#define DEFAULT_PORT "27015"

int main() 
{
    struct addrinfo hints =
    {
        0,
        AF_UNSPEC,
        SOCK_STREAM,
        IPPROTO_TCP,
        0,
        NULL,
        NULL,
        NULL,
    };
    struct addrinfo *result = NULL;
    getaddrinfo(DEFAULT_HOST, DEFAULT_PORT, &hints, &result);
    int sock = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
    connect(sock, result->ai_addr, (int)result->ai_addrlen);
    freeaddrinfo(result);
    #define sendbuf "this is a test"
    int n = send(sock, sendbuf, sizeof sendbuf - 1, 0);
    printf("Bytes sent: %d\n", n);
    shutdown(sock, SHUT_WR);
    char buf[32];
    n = recv(sock, buf, sizeof buf, 0);
    printf("Bytes received: %d\n", n);
    close(sock);
    return 0;
}